﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;
using System.Runtime.InteropServices;

namespace CitrixPVSWrapper
{
        public static partial class PvsHelpers
        {
            public static string ConvertToUnsecureString(this SecureString securePassword)
            {
                if (securePassword == null)
                    throw new ArgumentNullException("securePassword");

                IntPtr unmanagedString = IntPtr.Zero;
                try
                {
                    unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(securePassword);
                    return Marshal.PtrToStringUni(unmanagedString);
                }
                finally
                {
                    Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);
                }
            }
        }
    }
